Converting Byte[] to String - Interbase to C# - InvalidCastException

Posted by NorthernOutpost on Stack Overflow See other posts from Stack Overflow or by NorthernOutpost
Published on 2012-11-25T04:22:38Z Indexed on 2012/11/25 5:03 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

I'm using OleDbDataReader rdr to read a "Comments" field in BLOB form (sub_type 1 segment size 80) into a string from an Interbase DB, and I keep getting exceptions. Any suggestions?

Attempt #1

ls_Chap_Comments.Add((rdr["Comments"]).ToString());

InvalidCastException: The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable."

Attempt #2

byte[] b = new byte[100];
b = (byte[])rdr["Comments"];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);

InvalidCastException: Unable to cast object of type System.String to type System.Byte[]

Attempt #3

// 17 is the BLOB column zero-based location for "Comments"
retval = rdr.GetBytes(17, startIndex, outbyte, 0, bufferSize);    

InvalidCastException: Unable to cast object of type System.String to type System.Byte[].

Any suggestions would be really appreciated!

© Stack Overflow or respective owner

Related posts about c#

Related posts about string